package com.caimiao.miao.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.caimiao.miao.interfaces.BaseFragmentImpl;

import java.util.List;

public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
    private List<BaseFragmentImpl> mFragmentList;

    public SimpleFragmentPagerAdapter(FragmentManager fm, List<BaseFragmentImpl> fragmentList) {
        super(fm);
        mFragmentList = fragmentList;
    }

    public Fragment getPage(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        if (mFragmentList != null) {
            return mFragmentList.get(position % mFragmentList.size());
        }
        return null;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);//不调用FragmentTransaction.detach()
    }

    @Override
    public int getCount() {
        if (mFragmentList != null)
            return mFragmentList.size();
        return 0;
    }
}
